<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: zhangyi
// +----------------------------------------------------------------------

namespace app\crm\model;
use think\Model;
use think\Db;
use think\Cache;
use think\Loader;

class Priceauditprocess extends Model
{
    /**
     * 缓存审核价格流程
     */
    protected function processCache ()
    {
        $result = Db::name('order_process_node')->select();
        // 以步骤序号为键
        foreach ($result as $val) {
            $processCache[$val['step_num']] = $val;
        }
        Cache::set('processCache', $processCache);
    }
	
    public function priceAuditProcessDataList()
    {
		$page = $_REQUEST["page"];
		$limit = $_REQUEST["limit"];
        $count = Db::name('order_process_node')->count();
        // 查询状态为1的用户数据 并且每页显示10条数据
        $dataList = Db::name('order_process_node')->limit(($page-1)*$limit,$limit)->select();
        
        $rowsList = count($dataList) ? $dataList : false;
        $arrCate["code"] = 0;
        $arrCate["msg"] = '';
        $arrCate["count"] = $count;
        $arrCate["data"] = $rowsList;
        return $arrCate;
    }

	public function updateProcess()
	{
		$data = array(
			"step_num" => $_REQUEST["step_num"],
			"step_name" => $_REQUEST["step_name"],
			"next_step_num" => $_REQUEST["next_step_num"],
			"authorized_work_num" => $_REQUEST["authorized_work_num"]
		);
		$result = Db::name('order_process_node')->where('id', $_REQUEST["progress_id"])->update($data);
        $this->processCache();
		if ($result){
            echo json_encode(array('success'=>true,'msg'=>'更新成功！'));
        } else {
            echo json_encode(array('msg'=>'更新失败！'));
        }
	}
   





}